/********************************************************************
	Copyright (c) 2010-2020 by TnmuJoy
	@created:	17-10-2011   20:44
	@filename: 	Observer.hxx
	@author:	limiko lau(limiko.lau@gmail.com)
	@desc:		
*********************************************************************/
#ifndef TNMUJOY_GDUT_DESIGNPATTERN_OBSERVER_H_
#define TNMUJOY_GDUT_DESIGNPATTERN_OBSERVER_H_

#include <list>
namespace tnmujoy
{
namespace gdut
{

class Observer
{
public:
    virtual void update() = 0;
protected:
private:
};

class Subject
{
public:
    ~Subject(){}
    void attach(Observer* _observer)
    {
        observerTable_.push_front(_observer);
    }
    void decath(Observer* _observer)
    {
        if (_observer)
        {
            observerTable_.remove(_observer);
        }
    }
    void notify()
    {
        std::list<Observer*>::iterator itr = observerTable_.begin();
        for(; itr != observerTable_.end(); ++itr)
        {
            (*itr)->Update(this);
        }
    }
protected:
    Subject(){}
private:
    std::list<Observer*> observerTable_;
};
}//namespace gdut
}//namespace tnmujoy

#endif //TNMUJOY_GDUT_DESIGNPATTERN_OBSERVER_H_